package javabase.concurrent;


/**
 * 父线程在子线程启动前对共享变量额更新对子线程的可见性是有保证的
 * 父线程在子线程启动后对共享变量额更新对子线程的可见性是没有保证的
 */
public class ThreadStartVisibility {

    static volatile int data = 0;

    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(data);
        });

        data = 1;

        thread.start();


        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        data = 2;

    }

}
